/**
*      author: Y_Yao
*      created: 2024-10-06 20:18:16
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 9;



void solve()
{
    int n,d,k;
    cin >> n >> d >> k;
    vector<int> in(n+1,0);
    vector<int> out(n+1,0);
    int tk = k;
    while(tk--)
    {
        int l,r;
        cin >> l >> r;
        in[l]++;
        out[r]++;
    }

    int vmin = INF,vmax = -INF;
    int x,y;
    int cnt = 0;
    for(int i = 1;i <= d;i++)
    {
        if(in[i] > 0)
        {
            cnt += in[i];
        }
    }
    x = 1,y = 1;
    vmin = vmax = cnt;

    for(int i = d + 1;i <= n;i++)
    {
        //right meet in
        if(in[i] > 0)
        {
            cnt += in[i];
        }
        //left meet out
        if(out[i - d] > 0)
        {
            cnt -= out[i - d];
        }

        if(vmin > cnt) vmin = cnt,y = i - d + 1;
        if(vmax < cnt) vmax = cnt,x = i - d + 1;
    }

    cout << x << " " << y << endl;

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
        // in.clear();
        // out.clear();
    }
    return 0;
}